<?php foreach ($sections as $section) :?>
    <li id="<?php echo 'section_'.$section->getId()?>" class="closed">
        <span id="<?php echo 'span_section_'.$section->getId()?>" class="folder">
            <?php if($sf_user->hasCredential('Ver sección')): ?>
                <?php echo jq_link_to_remote(
                        $section->getTitle(),
                        array(
                            'update' => 'main',
                            'url'    => url_for('section_show',$section),
                            'before' => 'clearView();showLoaderMain();',
                            'complete' => 'hideLoader();',
                            'script' => true
                        )) ?>
            <?php else: ?>
                <?php echo $section->getTitle() ?>
            <?php endif; ?>
            <a id="<?php echo "section".$section->getId()."_menu_options"?>" tabindex="0" href="#menu_section_options"
                class="section_menu ui-button ui-widget ui-state-default ui-corner-all ui-button-icons-only"
                aria-disabled="false" title="Opciones">
                <span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
                <span class="ui-button-text">Opciones</span>
                <span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
            </a>
            <div id="menu_section_options" class="ui-helper-hidden-accessible">
                <ul>
                    <?php if($sf_user->hasCredential('Ver sección')): ?>
                        <li>
                            <?php echo jq_link_to_remote(
                                    '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Ver',
                                    array(
                                        'update' => 'main',
                                        'url'    => url_for('section_show',$section),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    )) ?>
                        </li>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Editar sección') &&
                            ($section->getType()->getType() == 'Register' ? $sf_user->hasCredential('Editar sección de registro') : true )): ?>
                        <li>
                            <?php echo jq_link_to_remote(
                                    '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Editar',
                                    array(
                                        'update' => 'main',
                                        'url'    => url_for('section_edit',$section),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    )) ?>
                        </li>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Crear sección')): ?>
                        <?php if($section->getType()->getType() != 'Home' && $section->getType()->getType() != 'Register'): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                        '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Agregar Subsección',
                                        array(
                                            'update' => 'main',
                                            'url'    => url_for('section_newsubsection',$section),
                                            'before' => 'clearView();showLoaderMain();',
                                            'complete' => 'hideLoader();',
                                            'script' => true
                                        )) ?>
                            </li>
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Crear contenido')): ?>
                        <?php if($section->getType()->getType() == 'News' && !$section->getNewsSection()->getUsesExternalFeed()): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                        '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Agregar Noticia',
                                        array(
                                            'update' => 'main',
                                            'url'    => url_for('content_new', $section),
                                            'before' => 'clearView();showLoaderMain();',
                                            'complete' => 'hideLoader();',
                                            'script' => true
                                        )) ?>
                            </li>
                        <?php elseif ($section->getType()->getType() == 'Gallery'): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                        '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Agregar '
                                        .$section->getGallerySection()->getContentType(),
                                        array(
                                            'update' => 'main',
                                            'url'    => url_for('content_new', $section),
                                            'before' => 'clearView();showLoaderMain();',
                                            'complete' => 'hideLoader();',
                                            'script' => true
                                        )) ?>
                            </li>
                        <?php elseif($section->getType()->getType() == 'Download'):?>
                            <li>
                                <?php echo jq_link_to_remote(
                                        '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Agregar '
                                        .$section->getDownloadSection()->getContentType(),
                                        array(
                                            'update' => 'main',
                                            'url'    => url_for('content_new', $section),
                                            'before' => 'clearView();showLoaderMain();',
                                            'complete' => 'hideLoader();',
                                            'script' => true
                                        )) ?>
                            </li>
                        <?php endif;?>
                    <?php endif;?>
                </ul>
            </div>
        </span>
        <?php $contents = $section->getContents()?>
        <?php $elements = $section->getElements()?>
        <?php if ($section->getHasSubsection() == 1 || $contents->count()>0 || $elements->count()>0):?>
            <ul id="<?php echo 'subsections_section_'.$section->getId()?>">
                <?php if($sf_user->hasCredential('Listar contenidos') && count($contents)>0): ?>
                    <li id="<?php echo 'section_'.$section->getId().'_contents'?>" class="closed">
                        <span class="folder">Contenidos</span>
                        <ul>
                            <?php include_partial('portal/sectionContents',
                                    array('contents' => $contents,
                                        'uses_comments' => $uses_comments
                                    ))?>
                        </ul>
                    </li>
                <?php endif; ?>
                <?php if($sf_user->hasCredential('Listar elementos') && count($elements)>0): ?>
                    <?php if($section->getType()->getType() == 'Home' || $section->getType()->getType() == 'Register'): ?>
                        <?php include_partial('portal/sectionElements', array('elements' => $elements)) ?>
                    <?php else: ?>
                        <li id="<?php echo 'section_'.$section->getId().'_elements'?>" class="closed">
                            <span class="folder">Elementos</span>
                            <ul>
                                <?php include_partial('portal/sectionElements', array('elements' => $elements)) ?>
                            </ul>
                        </li>
                    <?php endif; ?>
                <?php endif; ?>
                <?php if ($sf_user->hasCredential('Listar secciones') && $section->getHasSubsection() == 1): ?>
                    <?php include_partial('portal/tree',
                        array('sections' => $section->getChilds()))
                    ?>
                <?php endif; ?>
            </ul>
        <?php endif;?>
    </li>
<?php endforeach ?>